package com.gao.single;

import java.lang.reflect.Constructor;

// enum 是一个什么？本身也是一个Class类
public enum EnumSingle {
    INSTANCE;
    public EnumSingle getInstance(){
        return INSTANCE;
    }
}

class Test{
    public static void main(String[] args) throws Exception {
        EnumSingle instance1 = EnumSingle.INSTANCE;

//        java.lang.IllegalArgumentException: Cannot reflectively create enum object
        Constructor<EnumSingle> declaredConstructor = EnumSingle.class.getDeclaredConstructor (String.class,int.class);
        declaredConstructor.setAccessible(true);
        EnumSingle instance2 = declaredConstructor.newInstance();

//        EnumSingle instance2 = EnumSingle.INSTANCE;

//        java.lang.NoSuchMethodException: com.gao.single.EnumSingle.<init>()

        System.out.println(instance1);
        System.out.println(instance2);
        System.out.println(instance1 == instance2);
    }
}
